package bounce;

import junit.framework.TestCase;
import java.awt.Color;
import java.util.ArrayList;

/** 
 * Test cases to test BorderShape.
 * 
 * @author Ken Neth Yeoh
 *
 */

public class TestBorderShape extends TestCase {
	private MockPainter painter;
	
	public void setUp() {
		painter = new MockPainter();
	}
	
	public void testBasicWithinBorderBounce() {
		ArrayList<Shape> listOfShapes = new ArrayList<Shape>();
		listOfShapes.add(new RectangleShape(10, 50, -15, 15, 40, 40));
		listOfShapes.add(new BorderShape(listOfShapes.get(0)));
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		assertEquals("(rectangle 10,50,40,40)(rectangle 8,48,44,44)(rectangle 2,65,40,40)(rectangle 0,63,44,44)(rectangle 17,80,40,40)(rectangle 15,78,44,44)", painter.toString());
	}
	
	public void testDynamicWithinBorderBounce() {
		Color c = new Color(150, 150, 150);
		ArrayList<Shape> listOfShapes = new ArrayList<Shape>();
		listOfShapes.add(new DynamicRectangleShape(10, 50, -15, 15, 40, 40, c));
		listOfShapes.add(new BorderShape(listOfShapes.get(0)));
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		assertEquals("(rectangle 10,50,40,40)(rectangle 8,48,44,44)(rectangle 2,65,40,40)(set colour 150,150,150)(fill rect 2,65,40,40)(set colour 255,255,255)(rectangle 0,63,44,44)(rectangle 17,80,40,40)(set colour 150,150,150)(fill rect 17,80,40,40)(set colour 255,255,255)(rectangle 15,78,44,44)", painter.toString());
	}
	
	public void testBasicWithinBorderWithinBorderBounce() {
		ArrayList<Shape> listOfShapes = new ArrayList<Shape>();
		listOfShapes.add(new RectangleShape(10, 50, -15, 15, 40, 40));
		listOfShapes.add(new BorderShape(listOfShapes.get(0)));
		listOfShapes.add(new BorderShape(listOfShapes.get(1)));
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		listOfShapes = moveShapes(listOfShapes);
		listOfShapes = paintShapes(listOfShapes);
		assertEquals("(rectangle 10,50,40,40)(rectangle 8,48,44,44)(rectangle 6,46,48,48)(rectangle 2,65,40,40)(rectangle 2,63,44,44)(rectangle 0,61,48,48)(rectangle 2,80,40,40)(rectangle 17,78,44,44)(rectangle 15,76,48,48)", painter.toString());
	}
	
	public ArrayList<Shape> moveShapes(ArrayList<Shape> listOfShapes) {
		for(Shape s : listOfShapes) {
			s.move(1000, 1000);
		}
		return listOfShapes;
	}
	
	public ArrayList<Shape> paintShapes(ArrayList<Shape> listOfShapes) {
		for(Shape s : listOfShapes) {
			s.paint(painter);
		}
		return listOfShapes;
	}
}
